using System;
using System.Collections.Generic;

namespace DotConferenceSql
{
    /// <summary>
    /// Generic GROUP BY element
    /// </summary>
    public class GroupByQueryElement : QueryElementBase
    {
        private List<string> m_fields = new List<string>();
        /// <summary>
        /// Initializes a new instance of the <see cref="GroupByQueryElement"/> class.
        /// </summary>
        public GroupByQueryElement()
            : base()
        {
            Type = QueryElementType.GroupByClause;
        }

        /// <summary>
        /// Adds the specified field.
        /// </summary>
        /// <param name="field">The field.</param>
        public void Add(string field)
        {
            m_fields.Add(field);
        }

        /// <summary>
        /// Adds a range of fields
        /// </summary>
        /// <param name="field">The field.</param>
        public void AddRange(string[] field)
        {
            m_fields.AddRange(field);
        }

        /// <summary>
        /// Generate the part of the query for this element.
        /// </summary>
        /// <returns>generated SQL fragment</returns>
        public override string BuildTextQuery()
        {
            return String.Join(",", m_fields.ToArray());
        }
    }
}